import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, OneToOne, OneToMany } from 'typeorm';
import { Profile } from './Profile';
import { Order } from './Order'

// 实体类 映射为数据库里的一张表
// 创建的表默认名称为 类的名称小写  === user
// 可以指定名称 @Entity({name:"usertable"})
@Entity()
export class User {
    @PrimaryGeneratedColumn()
    id: number;

    @Column({ length: 50 })
    firstName: string;

    @Column({ length: 50 })
    lastName: string;

    @Column({ type: 'int' })
    age: number;

    @Column({ nullable: true, unique: true })       //unique唯一的
    email: string;

    @Column({ type: 'boolean', default: false })
    isActive: boolean;

    @CreateDateColumn()
    createdAt: Date;

    @UpdateDateColumn()
    updatedAt: Date;

    @OneToOne(() => Profile)
    profile: Profile;

    // 一对多 01
    @OneToMany(() => Order,(order)=>order.user)
    orders: Order[]
}
